<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /* 
      catch方法:
        - 当调用catch方法的promise实例变为失败状态,则会执行catch中的回调函数
        - catch的作用和then方法的第二个回调函数的作用一致
        - catch方法的返回值和then方法的返回值规则保持一致
    */

    const p1 = new Promise((resolve,reject)=>{
        console.log("请求数据a...");
        try{
            throw new Error("网络错误~~~")
            setTimeout(()=>{
                console.log("数据a请求成功!!!");
                resolve("数据a请求成功!!!")
            },3000)
        }catch(e){
            reject(e.message)
        }
    })
    console.log(p1);

    const p2 = p1.catch((reason)=>{
        console.log(reason);
        return new Promise((resolve,reject)=>{
            resolve(1)
        })

    })
    console.log(p2);

    
    </script>
</body>
</html>